<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <link rel="stylesheet" th:href="@{/static/element/index.css}"/>
</head>
<body>
<div id="app">
    <template>
        <el-card style="background-color: #f7f7f7">
            <el-form :model="queryForm" ref="queryForm" :inline="true" label-width="100px" @submit.native.prevent>
                <el-form-item label="请假类型" prop="type">
                    <el-select v-model="queryForm.type" placeholder="请选择请假类型" clearable
                               size="small">
                        <el-option
                                v-for="dict in typeOptions"
                                :key="dict.dictValue"
                                :label="dict.dictLabel"
                                :value="dict.dictValue"
                        />
                    </el-select>
                </el-form-item>
                <el-form-item label="标题" prop="title">
                    <el-input
                            v-model="queryForm.title"
                            placeholder="请输入标题"
                            clearable
                            size="small"
                            @keyup.enter.native="handleQuery"
                    />
                </el-form-item>
                <el-form-item label="开始时间" prop="startTime">
                    <el-date-picker clearable size="small" style="width: 200px"
                                    v-model="queryForm.startTime"
                                    type="date"
                                    value-format="yyyy-MM-dd"
                                    placeholder="选择开始时间">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="结束时间" prop="endTime">
                    <el-date-picker clearable size="small" style="width: 200px"
                                    v-model="queryForm.endTime"
                                    type="date"
                                    value-format="yyyy-MM-dd"
                                    placeholder="选择结束时间">
                    </el-date-picker>
                </el-form-item>


                <el-form-item>
                    <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                    <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">清空</el-button>
                </el-form-item>
            </el-form>
        </el-card>


        <el-table
                v-loading="loading"
                :data="tableData" row-key="id"
                :header-cell-style="{'text-align':'center','color':'#303133','font-weight':'600','background-color': '#F5F7FA'}"
                :cell-style="{'text-align':'center'}" border style="margin-top: 10px"
                @selection-change="handleSelectionChange"
        >
            <el-table-column label="ID" align="center" prop="id" width="50"></el-table-column>
            <el-table-column label="当前任务名称" align="center" prop="name">
                <template slot-scope="scope">
                    <el-tag
                            effect="dark" type="warning" v-if="scope.row.taskName=='未启动'">
                        {{scope.row.taskName}}
                    </el-tag>

                    <el-tag
                            effect="dark" type="success" v-else>
                        {{scope.row.taskName}}
                    </el-tag>
                </template>
            </el-table-column>
            <el-table-column label="流程实例ID" align="center" prop="proInstanceId"></el-table-column>
            <el-table-column label="任务ID" align="center" prop="taskId"></el-table-column>
            <el-table-column label="标题" align="center" prop="title"></el-table-column>
            <el-table-column label="原因" align="center" prop="reason"></el-table-column>
            <el-table-column label="开始时间" align="center" prop="startTime" show-overflow-tooltip="true">
                <template slot-scope="scope">
                    <span>{{ scope.row.startTime}}</span>
                </template>
            </el-table-column>
            <el-table-column label="结束时间" align="center" prop="endTime" show-overflow-tooltip="true">
                <template slot-scope="scope">
                    <span>{{ scope.row.endTime}}</span>
                </template>
            </el-table-column>
            <el-table-column label="请假时长" align="center" prop="totalTime"></el-table-column>
            <el-table-column label="申请人" align="center" prop="applyUser"></el-table-column>
            <el-table-column label="申请时间" align="center" prop="applyTime" show-overflow-tooltip="true">
                <template slot-scope="scope">
                    <span>{{ scope.row.applyTime}}</span>
                </template>
            </el-table-column>


            <el-table-column label="操作选项" align="center">
                <template slot-scope="scope">
                    <el-menu :default-active="activeIndex" class="el-menu-demo" mode="horizontal"
                    >
                        <el-submenu index="1">
                            <template slot="title">操作选项</template>
                            <el-menu-item index="2-1"
                                          @click="handleAddOrUpdate(2,scope.row)">申请详情
                            </el-menu-item>
                            <el-menu-item index="2-2" @click="approve(scope.row)">
                                审批表单
                            </el-menu-item>
                            <el-menu-item index="2-3">审批历史</el-menu-item>
                            <el-menu-item index="2-4" @click="viewProcess(scope.row)">
                                进度查看
                            </el-menu-item>
                            <el-menu-item index="2-5">转办申请
                            </el-menu-item>

                        </el-submenu>
                    </el-menu>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination
                background
                :page-sizes="[10, 20, 30, 40,50]"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total"
                :page-size.sync="pageSize"
                :current-page.sync="currentPage"
                @size-change="handleQuery"
                @current-change="handleQuery"
                style="float: right;margin-top: 10px"
        />
    </template>
</div>
</body>
<script th:src="@{/static/js/axios.min.js}"></script>
<script th:src="@{/static/js/request.js}"></script>
<script th:src="@{/static/js/common.js}"></script>
<script th:src="@{/static/api/admin/bizLeave.js}"></script>
<script th:src="@{/static/js/vue.min.js}"></script>
<script th:src="@{/static/element/index.js}"></script>
<script th:src="@{/static/js/jquery.min.js}"></script>
<script th:src="@{/static/layer/layer.js}"></script>
<script>
    new Vue({
        el: '#app',
        data() {
            return {
                currentPage: 1,
                activeIndex: '1',
                pageSize: 10,
                total: 0,
                tableData: [],
                multipleSelection: [],
                // 请假类型字典
                typeOptions: [],
                button: {
                    add: false,
                    update: false,
                    delete: false
                },
                loading: false,
                queryForm: {
                    roleName: ''
                }
            }
        },
        created() {
            this.handleQuery();
            let sysButtons = JSON.parse(localStorage.getItem("mars-sysButtons"));
            this.button.add = sysButtons.indexOf("admin/bizLeave/add") > -1;
            this.button.update = sysButtons.indexOf("admin/bizLeave/update") > -1;
            this.button.delete = sysButtons.indexOf("admin/bizLeave/delete") > -1;
            getDicts("leave_type").then(response => {
                this.typeOptions = response.data;
            });

        },
        methods: {
            submitApply(row) {
                let params = {}
                params.businessKey = row.id
                params.flowName = "请假流程"
                params.flowKey = "leave_test"

                requests.post("/admin/bizLeave/submitProcess", params).then(res => {
                    if (res.code === '200') {
                        this.$notify({
                            title: '成功',
                            message: '提交成功',
                            type: 'success'
                        });
                        this.handleQuery()
                    }
                })
            },
            viewProcess(row) {
                requests.post("/workflow/image/readProcessImg", {proInstanceId: row.proInstanceId})
                    .then((res) => {
                        if (res.code === '200') {
                            openMiddlePage('审批进度', '/workflow/processImg.html?img=' + res.data, this)
                        }
                    });

            },
            handExportData() {
                let queryParam = this.queryForm
                queryParam.pageNo = this.currentPage
                queryParam.pageSize = -1
                exports('/admin/bizLeave/export', queryParam).then(res => {
                    this.$notify({
                        title: '成功',
                        message: '导出成功',
                        type: 'success'
                    });
                });
            },
            approve(row) {
                openPage('审批表单', '/admin/bizLeave/bizLeaveApprove.html?id=' + row.id + "&proInstanceId=" + row.proInstanceId + "&taskId=" + row.taskId, this);
            },
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },
            batchHandleDelete() {
                let params = {}
                if (this.multipleSelection.length === 0) {
                    this.$notify({
                        title: '失败',
                        message: '请选择删除行',
                        duration: 2000
                    });
                    return
                }
                deleteById('/admin/bizLeave/delete/' + this.multipleSelection.map((item) => item.id), this);
            },
            switchChange(row) {
                this.formData = row
                update(this.formData).then(res => {
                    if (res.code === '200') {
                        this.$notify({
                            title: '成功',
                            message: '操作成功',
                            type: 'success'
                        });
                    }
                })
            },

            typeFormat(row, column) {
                return selectDictLabel(this.typeOptions, row.type);
            },
            resetQuery() {
                this.queryForm = {}
                this.handleQuery()
            },


            handleCurrentChange(val) {
                this.currentPage = val;
                this.handleQuery();
            },
            handleSizeChange(val) {
                this.pageSize = val;
                this.handleQuery();
            },
            handleQuery() {
                let queryParam = this.queryForm
                queryParam.pageNo = this.currentPage
                queryParam.pageSize = this.pageSize
                queryParam.businessType = 2
                this.loading = true
                pageList(queryParam).then((res) => {
                    if (res.code === '200') {
                        this.tableData = res.data.list;
                        this.total = res.data.count;
                        this.loading = false
                    } else {
                        this.loading = false;
                        this.$notify({
                            title: '失败',
                            message: res.message,
                            type: 'error'
                        });
                    }
                });
            },
            handleDelete(row) {
                deleteById('/admin/bizLeave/delete/' + row.id, this);
            },

            handleAddOrUpdate(type, row) {
                if (type === 1) {
                    openPage('新增请假', '/admin/bizLeave/bizLeaveAddUpdate.html', this);
                } else {
                    openPage('表单详情', '/admin/bizLeave/bizLeaveAddUpdate.html?id=' + row.id + "&source=todo", this);
                }
            },
        }
    });
</script>
</html>
